﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace Rename.UC.组合
{
    public partial class Uc中间主界面 : UserControl
    {
        
        public Uc中间主界面(OLSVType olsvType)
        {
            if (DesignMode)
            {
                InitializeComponent();
            }
            else
            {
                InitializeComponent1(olsvType);
            }
            ucBtn文件添加拖拽.Location = new Point((this.Width - 400) / 2, (this.Height - 188) / 2 - 80);
        }

        public Uc添加拖拽文件 UcButton添加拖拽文件
        {
            get => this.ucBtn文件添加拖拽;
        }
        public Uc中间列表 Uc中间列表
        {
            get => this.ucLsv清空列表;
        }

        #region 自定义事件
        /// <summary>
        /// 清空列表事件
        /// </summary>
        private EventHandler<EventArgs> _clearFileHandler;
        public event EventHandler<EventArgs> ClearFileHandler
        {
            add { _clearFileHandler += value; }
            remove { _clearFileHandler -= value; }
        }
        protected void OnClearFile(EventArgs e)
        {
            var temp = System.Threading.Volatile.Read(ref _clearFileHandler);
            if (temp != null)
            {
                temp(this, e);
            }
        }

        #endregion
        private void UcLsv清空列表_ClearListViewItem(object sender, EventArgs e)
        {
            ucLsv清空列表.Visible = false;
            ucBtn文件添加拖拽.Visible = true;
            OnClearFile(e);
        }

        public string ListItemCount
        {
            get => null; //ucLsv清空列表.UcListView.Items.Count.ToString();
        }

        /// <summary>
        /// 添加文件
        /// </summary>
        /// <param name="files">文件名</param>
        /// <param name="rule">重命名规则</param>
        /// <param name="fn">回调返回文件总数</param>
        public void AddFile(string[] files,string rule,Action<int> fn)
        {
            ucBtn文件添加拖拽.Visible = false;
            ucLsv清空列表.Visible = true;
            ucLsv清空列表.Dock = DockStyle.Fill;
            ucLsv清空列表.UcFastOLSV.SetDataSource(files, rule, fn);
        }

        public async void AddFileAsync(string[] files, string rule,Action<int> fn)
        {
            ucBtn文件添加拖拽.Visible = false;
            ucLsv清空列表.Visible = true;
            ucLsv清空列表.Dock = DockStyle.Fill;
            await ucLsv清空列表.UcFastOLSV.SetDataSourceAsnyc(files, rule,fn);
        }

        private void UcFileAddMain_Load(object sender, EventArgs e)
        {
            ucLsv清空列表.Visible = false;
        }
    }
}
